package net.yambal.RTM.RestWrapper
{
	//import net.yambal.Utilty.MD5;
	import com.adobe.crypto.MD5;
	
	public class RestParameters
	{
		private var _seed_params:Array;
		private var _params:Array;
		private var _obj_params:Object;
		
		public function RestParameters()
		{
			this._seed_params = new Array();
			this._params = new Array();
			this._obj_params = new Object();
		}
		
		public function addParam(name:String, val:String):void{
			if(val && name && name.toLowerCase() != "null" && name.length != 0){
				this._seed_params.push(name + val);
				this._params.push(name + "=" + val);
				this._obj_params[name] = val;
			}
		}
		
		public function getApiSig(shared_secret:String):String{
			this._seed_params.sort();
			var seed:String = shared_secret + this._seed_params.join("");
			return MD5.hash(seed);
		}
		
		public function getParameterString():String{
			this._params.sort();
			return this._params.join("&");
		}
		
		public function getParameterStringWithSig(shared_secret:String):String{
			return this.getParameterString() + "&api_sig=" + this.getApiSig(shared_secret);
		}
		
		public function getParameterObjectWithSig(shared_secret:String):Object{
			this._obj_params.api_sig = this.getApiSig(shared_secret);
			return this._obj_params;
		}
		
		public function getParameterObject():Object{
			return this._obj_params;
		}
	}
}